from django.db import models
from tagging.fields import Tag, TagField
import tagging

# Create your models here.
class Post(models.Model):
    title = models.CharField(max_length=100)
    slug = models.CharField(max_length=100, null=True, blank=True)
    date = models.DateField('Date published')
    time = models.TimeField('Time published')
    content = models.TextField(max_length=100000)
    tags = TagField()
    
    class Meta:
        ordering = ['-date', '-time']
        verbose_name = 'Blog Post'
        
    class Admin:
        list_display = ('title', 'content', 'datetime')
    
    def __unicode__(self):
        return self.title
    
    def _get_tags(self):
        return Tag.objects.get_for_object(self)

    def _set_tags(self, tag_list):
        Tag.objects.update_tags(self, tag_list)
        
try:
    tagging.register(Post, tag_descriptor_attr='taglist')
except tagging.AlreadyRegistered:
    pass